/**
 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be
 * useful, but WITHOUT ANY WARRANTY. See the GNU General Public License for more details. Copyright (C) 2011 CellObject.net
 */
package net.cellobject.sqlitexmlbrowser.shared;

import com.android.ddmlib.FileListingService.FileEntry;
import com.android.ddmlib.IDevice;
import com.android.ddmlib.SyncService;
import com.android.ddmlib.SyncService.ISyncProgressMonitor;
import com.android.ddmuilib.console.DdmConsole;
import com.android.ddmuilib.explorer.DeviceExplorer;

public class DeviceExplorerAccessor {
	public static void pullFile(final DeviceExplorer mExplorer, final FileEntry fileEntry, final String tempFilePath) {
		final IDevice mCurrentDevice = (IDevice)PrivateAccessor.getPrivateField(mExplorer, "mCurrentDevice");
		try {
			final SyncService sync = mCurrentDevice.getSyncService();
			final ISyncProgressMonitor monitor = SyncService.getNullProgressMonitor();
			sync.pullFile(fileEntry, tempFilePath, monitor);
			sync.close();
		} catch (final Exception e) {
			DdmConsole.printErrorToConsole("Failed to open file " + fileEntry.getName());
			DdmConsole.printErrorToConsole(e.getMessage());
		}
	}
}
